package com.ywb.ex04;

import java.util.concurrent.TimeUnit;

public class Task1 implements Runnable{
    int count = 10;
    @Override
    public void run() {
        while(true){
            try {
                TimeUnit.MILLISECONDS.sleep(100);
            } catch (InterruptedException ie) {
                ie.printStackTrace();
            }
            synchronized (this) {
                if(count> 0) {
                    System.out.println("车票还剩下" + --count + "张," + Thread.currentThread().getName() + "抢到1张");
                }
            }
        }
    }

    public static void main(String[] args) {
        Task1 task = new Task1();
        new Thread(task, "A").start();
        new Thread(task, "B").start();
        new Thread(task, "C").start();
        new Thread(task, "D").start();

    }
}

